package day21.edu;

import day20.edu.Person;
import org.junit.Test;

import java.util.*;

// Created: 21/09/2025, ChangJiang Ru
public class CollectionTest {
    @Test
    public void test1()
    {
        Collection coll = new ArrayList();

        coll.add("AA");
        coll.add(123);
        coll.add(new Object());
        coll.add(new Person("Jack", 14));
        coll.add("GreatFree");

        System.out.println(coll);

        System.out.println(coll.size());

        Collection coll1 = new ArrayList();
        coll1.add("BB");
        coll1.add(456);

        coll.addAll(coll1);
        System.out.println(coll);
        System.out.println(coll.size());
    }

    @Test
    public void test2()
    {
        Collection coll = new ArrayList();
        coll.add("AA");
        coll.add("GreatFree");
        Collection coll1 = new ArrayList();
        coll1.add("BB");
        coll1.add("New www");
        coll.addAll(coll1);
        System.out.println(coll);

        coll.add(coll1);
        System.out.println(coll);

        System.out.println(coll.isEmpty());
        coll.clear();
        System.out.println(coll);
        System.out.println(coll.size());
    }

    @Test
    public void test3()
    {
        Collection coll = new ArrayList();
        coll.add("AA");
        coll.add("GreatFree");
        System.out.println(coll);

        Object[] obj = coll.toArray();
        System.out.println(Arrays.toString(obj));
    }

    @Test
    public void test4()
    {
        String[] arr = new String[]{"AA", "BB", "CC"};
        Collection list = Arrays.asList(arr);
        System.out.println(list);
    }
    @Test
    public void test5()
    {
        Collection coll = new ArrayList();
        coll.add("AA");
        coll.add("GreatFree");
        Iterator iterator = coll.iterator();
        for (int i = 0; i < coll.size(); i++) {
            System.out.println(iterator.next());
        }

        while(iterator.hasNext())
        {
            System.out.println(iterator.next());
        }

        for (Object obj : coll) {
            System.out.println(obj);
        }
    }

    @Test
    public void test6()
    {
        int[] arr = new int[]{1,2,3,4,5,6,7,8,9,10};
        for(int i : arr)
        {
            if(i == 10)
            {
                System.out.println(i);
                break;
            }
            System.out.print(i + ",");
        }
    }

    @Test
    public void test7()
    {
        int[] arr = new int[]{1,2,3,4,5,6,7,8,9,10};
        for (int i : arr)
        {
            if(i < 10)
            {
                System.out.print(i + ", ");
            }else
            {
                System.out.print(i);
            }
        }
    }
    
    @Test
    public void test8()
    {
        String[] arr1 = new String[]{"AA", "BB", "CC"};
        for (int i = 0; i < arr1.length; i++) {
            arr1[i] = "MM";
        }

        for(String s : arr1)
        {
            System.out.println(s);
        }
    }

    @Test
    public void test9()
    {
        List list = new ArrayList();
        list.add("AA");
        list.add(123);
        list.add(new Person("Tom", 12));
        System.out.println(list);

        list.add(2, "cc");
        System.out.println(list);

        List list1 = Arrays.asList(1,2,3);
        list.add(1, list1);
        list.addAll(1,list1);
        System.out.println(list);

        list.remove(2);
        System.out.println(list);
        System.out.println(list.get(2));
    }


}
